#include <bits/stdc++.h>
using namespace std;
string pre, in;

struct node{
    char c;
    node *l, *r;
    node():c(0), l(nullptr), r(nullptr){}
};

node* solve(int p1, int p2, int i1, int i2){
    if(p1>p2) return nullptr;
    node *u = new node;
    u->c = pre[p1];
    int i = in.find(u->c);
    int lcnt = i-i1, rcnt = i2-i;
    u->l = solve(p1+1, p1+lcnt, i1, i-1);
    u->r = solve(p2-rcnt+1, p2, i+1, i2);
    return u;
}

void post(node *u){
    if(!u) return;
    post(u->l);
    post(u->r);
    cout << u->c;
}

void del(node *u){
    if(!u) return;
    del(u->l);
    del(u->r);
    delete(u);
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T = 0;
    while(cin >> pre >> in){
        node *r = solve(0, pre.size()-1, 0, in.size()-1);
        post(r);
        cout << '\n';
        del(r);
    }
    return 0;
}